<?php
	class PlanDisplayHelper extends AppHelper
	{
		var $helpers = array("Javascript","Html");
		function newListingPlanInput($categoryIds,$manipluateFields = false)
		{
			if(!isset($this->Html))
			{
				$this->initHelper("Html");
			}
			$this->Html->css("/paid_listings/css/style.css",array(),null,false);
			$plans = cri("PaidListings.Plan")->getNewListingPlans($categoryIds);
			return $this->showPlans($plans,$manipluateFields);
		}
		
		function showPlans($plans,$manipluateFields = false)
		{
			return $this->getView()->element("plans_input",array("plans"=>$plans,'plugin'=>"paid_listings",'manipluateFields'=>$manipluateFields));
		}
		
		function beforeRender()
		{
			$View = $this->getView();
			if(isset($View->params['admin']) && $View->params['admin'] == 1 && ($this->params['plugin'] == "paid_listings"))
			{
				$navHtml = "";
				$anchors = array(
					"settings"=>array('title'=>__('Settings'),'url'=>array('action'=>"setting",'controller'=>"paid_listing_config")),
					'payment_gateways'=> array("title"=>__("Payment gateways"),'url'=>array("action"=>"index",'controller'=>"payment_handlers")),
					'plans' => array('title'=>__("Plans"),'url'=>array("controller"=>"plans","action"=>"index")),
                    'revenue_sumary' => array('title'=>__("Revenue Report"),'url'=>array("controller"=>"orders","action"=>"dashboard")), 
					'orders'=> array("title"=>__("Orders"),'url'=>array("controller"=>"orders",'action'=>"index"))
				);	
				foreach($anchors as $anchor)
				{
					$activeClss = "";
					if($anchor['url']['controller'] == $this->params['controller'])
					{
                        $activeClss = "subnav_selected";
                        if($this->params['controller'] == "orders")
                        {
                          if(($anchor['url']['action'] == "dashboard" && $this->params['action'] != "admin_dashboard") || ($anchor['url']['action'] == "index" && $this->params['action'] == "admin_dashboard") )
                          {
                            $activeClss = "";
                          }
                        }
					}
					$navHtml .= "<li class=\"$activeClss\">".$this->Html->link($anchor['title'],$anchor['url'],array())."<li>";
				}
				$navHtml = '<div class="subnav">'.$navHtml.'</div>';
				$navHtmlJson = $this->Javascript->object($navHtml);
				$js =<<<JS
				(function()
				{
					var html = $navHtmlJson;
					\$('.breadcrumb').after($navHtmlJson);
					//\$('.breadcrumb').hide();	
					
				})();
JS;
				$this->Html->css('/paid_listings/css/nav_tab.css',null,array(),false);
				$this->Javascript->startup($js);
			}
			parent::beforeRender();
		}
	}
?>
